package cn.com.ht.springbootjpa.springbootjpa_more.controller;

import cn.com.ht.springbootjpa.springbootjpa_more.domain.primary.User;
import cn.com.ht.springbootjpa.springbootjpa_more.domain.second.Role;
import cn.com.ht.springbootjpa.springbootjpa_more.domain.second.RoleRepository;
import cn.com.ht.springbootjpa.springbootjpa_more.domain.primary.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Controller {


    @Autowired
    private UserRepository userRepository;

    @Autowired
    private RoleRepository roleRepository;

    @GetMapping(value = "/addUser")
    public void addUser(){
        User user = new User();
        user.setAge(11);
        user.setName("aaa");
        userRepository.save(user);
    }

    @GetMapping(value = "/getUsers")
    public List<User> getUser(){
        return userRepository.findAll();
    }

    @GetMapping(value = "/addRole")
    public void addRole(){
        Role role = new Role();
        role.setName("bbbb");
        role.setRole_desc("ccccc");
        roleRepository.save(role);
    }

    @GetMapping(value = "/getRoles")
    public List<Role> getRoles(){
        return roleRepository.findAll();
    }

}
